﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Kira.Compiler.Bods
{
    [XmlElementMapping("DIDatabaseDatastore")]
    public class DIDatabaseDatastore : BodsObject
    {

    }

    [XmlElementMapping("DSConfiguration")]
    public class DSConfiguration : BodsElementBase
    {
        public String Name
        {
            get
            {
                return this.GetAttrbuteValue("name");
            }
        }
        public bool IsDefault
        {
            get
            {
                return bool.Parse(this.GetAttrbuteValue("default"));
            }
        }

        public override IEnumerable<BodsElementBase> Elements
        {
            get
            {
                return new BodsElementBase[] { };
            }
        }

        private List<BodsElementAttribute> _configs;
        public IEnumerable<BodsElementAttribute> Configs
        {
            get
            {
                if (this._configs == null)
                {
                    this._configs = (from c in this.Xml.Elements() select new BodsElementAttribute() { Name = c.Name.ToString(), Value = c.Value }).ToList();
                }
                return _configs;
            }
        }

        public bool HasConfig(String configName)
        {
            return this.Configs.Any(c => c.Name.ToUpper() == configName.ToUpper());
        }

        public String GetConfig(String configName)
        {
            return this.Configs.Single(c => c.Name.ToUpper() == configName.ToUpper()).Value;
        }
    }
}
